<template>
  <div class="list">
    <!-- 面包蟹 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索框 -->
    <div style="margin-top: 15px;">
      <el-input
        placeholder="请输入内容"
        class="input-with-select"
        v-model="listObj.query"
        @keyup.enter.native='init()'
        style="width:300px"
      >
        <el-button @click="init()" slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <!-- 按钮添加 -->
      <el-button @click="$router.push({name: 'add'})" style="margin-left:30px" type="success" plain>添加按钮</el-button>
    </div>
    <!-- 列表项 -->
    <el-table :data="goodsList" highlight-current-row style="width: 100%; border:1px;">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column prop="goods_name" label="商品名称" width="380"></el-table-column>
      <el-table-column prop="goods_price" label="商品价格" width="120"></el-table-column>
      <el-table-column prop="goods_state" label="商品状态"></el-table-column>
      <el-table-column prop="goods_weight" label="商品重量"></el-table-column>
      <el-table-column prop="add_time" label="创建时间"></el-table-column>

      <el-table-column label="操作" style="padding:0; margin:0;">
        <template slot-scope="scope">
          <el-button size="mini">编辑</el-button>
          <el-button size="mini" type="danger">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="listObj.pagenum"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="listObj.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>
  </div>
</template>


<script>
import { getGoodList } from "@/api/list.js";
export default {
  data() {
    return {
      //goodsList装返回的数据
      goodsList: [],
      total: 0,
      listObj: {
        query: "",
        pagenum: 1, //当前页
        pagesize: 10 //一页显示10条
      }
    };
  },
  methods: {
    handleSizeChange(val) {
      this.listObj.pagesize = val;
      this.init();
    },
    handleCurrentChange(vals) {
      this.listObj.pagenum = vals;
      this.init();
    },
    init() {
      getGoodList(this.listObj).then(res => {
        // console.log(res);
        // console.log(this.listObj)
        if (res.data.meta.status === 200) {
          console.log(res);
          this.goodsList = res.data.data.goods;
          this.total = res.data.data.total;
        }
      });
    }
  },
  mounted() {
    this.init();
  }
};
</script>
<style lang="less" scoped>
</style>

